#include "modbus_register.h"
#include "ice_cream_process.h"

// 果酱模块读取处理
uint16_t modbus_jam_get(uint16_t address) {

    ice_cream_process_data_t *process_data=  ice_icream_process_data_get();
    int jamid=    (address-REG_JAM1_POS_BASE)/(REG_JAM1_REMAIN_COUNT-REG_JAM1_POS_BASE);
    int jamvalueid=  (address-REG_JAM1_POS_BASE)%(REG_JAM1_REMAIN_COUNT-REG_JAM1_POS_BASE);
    uint16_t *jam_param= (uint16_t*)&process_data->config.jams[jamid].add_pos;
   switch (jamvalueid+REG_JAM1_POS_BASE)
    {
     case REG_JAM1_TIME_BASE:
         return jam_param[jamvalueid]/1000;
     case REG_JAM1_TIME_BASE+1:
        return jam_param[jamvalueid]/1000;

    }
    return jam_param[jamvalueid];
}

// 果酱模块写入处理
void modbus_jam_set(uint16_t address, uint16_t value) {


    ice_cream_process_data_t *process_data=  ice_icream_process_data_get();
    int jamid =    (address-REG_JAM1_POS_BASE)/(REG_JAM1_REMAIN_COUNT-REG_JAM1_POS_BASE);
    int jamvalueid =  (address-REG_JAM1_POS_BASE)%(REG_JAM1_REMAIN_COUNT-REG_JAM1_POS_BASE);
    uint16_t *jam_param= (uint16_t*)&process_data->config.jams[jamid].add_pos;
    jam_param[jamvalueid]=value;
    switch (jamvalueid+REG_JAM1_POS_BASE)
    {
     case REG_JAM1_TIME_BASE:
          jam_param[jamvalueid]=value*1000;
     case REG_JAM1_TIME_BASE+1:
         jam_param[jamvalueid]=value*1000;

    }

}
    